package org.agony2d.view 
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import org.agony2d.notify.AEvent;
	import org.agony2d.notify.AEvent;
	import org.agony2d.view.supportClasses.AbstractImageButton;
	import org.agony2d.view.supportClasses.ImageCheckBoxProp;
	
	import org.agony2d.core.agony_internal;
	use namespace agony_internal;
	
	[Event(name = "change", type = "org.agony2d.notify.AEvent")]
	
final public class ImageCheckBox extends AbstractImageButton 
{
	
	public function ImageCheckBox( imageData:*, selected:Boolean = false, isCenter:Boolean = false, isPressChange:Boolean = false ) 
	{
		super(imageData, isCenter);
		m_selected = selected
		if (isPressChange)
		{
			this.addEventListener(AEvent.PRESS, ____onChange)
		}
		else
		{
			this.addEventListener(AEvent.CLICK, ____onChange)
		}
	}
	
	
	final public function get selected() : Boolean { return m_selected; }
	final public function set selected( b:Boolean ) : void
	{
		if (m_selected != b)
		{
			m_selected = b;
			if (!this.interactive && prop.hasInvalid)
			{
				m_invalidListener.execute()
			}
			
			else
			{
				m_releaseListener.execute();
			}
			this.dispatchDirectEvent(AEvent.CHANGE)
		}
	}
	
	
	final agony_internal function get prop() : ImageCheckBoxProp { return m_prop as ImageCheckBoxProp }
	
	
	final agony_internal function ____onChange( e:AEvent ) : void
	{
		this.selected = !this.selected
	}
	
	override agony_internal function onRelease() : void
	{
		m_bitmap.bitmapData = m_selected ? prop.selectedRelease : m_prop.release
	}
	
	override agony_internal function onPress() : void
	{
		m_bitmap.bitmapData = m_selected ? prop.selectedPress : m_prop.press
	}
	
	override agony_internal function onLeave() : void
	{
		if (this.pressed)
		{
			m_bitmap.bitmapData = m_selected ? prop.selectedLeave : m_prop.leave
		}
	}
	
	override agony_internal function onHover() : void
	{
		if (this.pressed)
		{
			m_bitmap.bitmapData = m_selected ? prop.selectedHover : m_prop.hover
		}
	}
	
	override agony_internal function onInvalid() : void
	{
		m_bitmap.bitmapData = m_selected ? prop.selectedInvalid : m_prop.invalid
	}
	
	
	agony_internal var m_selected:Boolean;
}
}